<template>
  <view class="flex-col">

    <view :class="boole?'bottom115':''">
      <apply-message v-model="ruleForm"/>

      <disposal-result ref="refDisposalResult" v-model="ruleForm" :boole="boole"/>

    </view>

    <view class="button-container" v-if="boole">
      <button class="btn-item" @click="submit">提 交</button>
    </view>

  </view>
</template>

<script>
import * as apis from '@/api/routineHandle'
import applyMessage from "./components/applyMessage.vue"
import disposalResult from "./components/disposalResult.vue"

export default {
  name: 'result',
  components: {applyMessage, disposalResult},
  computed: {},
  watch: {},
  data() {
    return {
      ruleForm: {
        underwriterId: '',
        underwriterName: '',
        finalPrice: '',
        priceDifference: '',
        routineRemark: '',
        routineAttachmentOss: '',
        underwriterType: ''
      },
      boole: false
    };
  },
  onLoad(op) {
    if (op?.type === "edit") {
      this.boole = true;
    }
    if (op?.type === "view") {
      this.boole = false;
    }
    this.handleDetail(op?.id)
  },
  methods: {
    async handleDetail(id) {
      try {
        const res = await apis?.vehicleDisposalDetails(id)
        for (let key in res.data) {
          this.$set(this.ruleForm, key, res.data[key])
        }
        if (typeof this.ruleForm.underwriterType === 'string') {
          this.ruleForm.underwriterType = JSON.parse(this.ruleForm.underwriterType) || []
        }
      } catch (e) {
        console.error(e)
      }
    },

    async submit() {

      try {
        await this.$refs.refDisposalResult.handleEffect()

        uni.showLoading();

        this.ruleForm.underwriterType = JSON.stringify(this.ruleForm.underwriterType)

        let res = await apis?.vehicleDisposal(this.ruleForm);

        if (res.code === 200) {
          uni.$emit("refBackList", true);
          this.$modal.msgSuccess("提交成功");
          setTimeout(() => {
            this.$tab.navigateBack();
          }, 1000);
        }
      } catch (error) {
        if (typeof error === 'string') {
          this.$nextTick(() => {
            uni.pageScrollTo({
              selector: error,
            });
          });
        } else {
          console.error(error)
        }
      } finally {
        setTimeout(()=>{uni.hideLoading()},1000)
      }
    }
  },
};
</script>

<style scoped lang=""></style>


